﻿#include "workerthreadx.h"
template<typename m_>
bool workerthreadx::InitInstance()
{
	DWORD     Ret;
	WSADATA   wsaData;

	if ((Ret = WSAStartup(0x0202, &wsaData)) != 0)
		return free();
	return threadx_::InitInstance();
}
template<typename m_>
void workerthreadx::MainFunction()
{
	int nRet;
	int PrintDebugInfo_Flag=0;

	DWORD			 dwCumId;
    OVERLAPPED      *Overlap;
    pper_io_objx_	pverlapobject;
            
    DWORD           dwBytesXfered;
	HANDLE			g_CompletionPort=m_piocpx->m_hCompletionPort;

    while(m_piocpx->m_brunning)
	{		
		DWORD dwMilliseconds  =   1000;
		
		nRet= GetQueuedCompletionStatus(g_CompletionPort,&dwBytesXfered,(unsigned long *)&dwCumId,&Overlap,dwMilliseconds);
		if(nRet==0 && Overlap==NULL)	//超时
			continue;
				
		pverlapobject = (pper_io_objx_)Overlap;	
		
		m_piocpx->handle_complate_notify(dwBytesXfered,(tcplinkx_<m_>*)dwCumId,pverlapobject);
	
	}	
}
